var app = require('../app'),
    loading = require('../../modules/loading'),
    formMod = require('../../modules/form');
    lockfas = false;

var updatacaseid = "",
    updataid = "";
$('#confirm')
.on('show.bs.modal', function (event) {
    var button = $(event.relatedTarget),
        type = button.data("type"),
        modal = $(this);
        updatacaseid = button.attr("data-caseid");
        updataid = button.attr("data-id");
});
$('body')
.on('change','#zttype', function(){
    var type = $(this).val();
    window.location.replace ('/entryrepay/index?type='+type);
})
.on('change','#newzttype', function(){
    var type = $(this).val();
    window.location.replace ('/entryrepay/list?type='+type);
})
.on('click','#confirmSubmit',function(){
    // loading.showLoading({
    //     type: 1,
    //     tip: '上传中...'
    // })
    var fd = new FormData();
    console.log($("#exampleInputFile")[0].files[0])
    var file_obj = $("#exampleInputFile")[0].files[0];
    if(!file_obj){
        toastr.warning("您没有选择任何文件");
        return;
    }
    fd.append('file', file_obj);
    fd.append('case_id', updatacaseid);
    fd.append('id', updataid);
    $.ajax({
        url: '/entryrepay/uploadRepayEvidence',
        type: 'post',
        data: fd,
        //文件上传时必须配置的参数
        contentType: false,
        processData: false,
        dataType: "json",
        success : function(res){
            uploadingState = 0;
            if(res.code == 200){
                // loading && loading.hideLoading();
                toastr.success("文件上传完毕");
                $("#confirm").modal("hide");
            }else{
                // loading && loading.hideLoading();
                toastr.warning(res.message);
            }
        },
        error : function(){
            // loading && loading.hideLoading();
            toastr.error("服务器异常");
        }
    });
   return false;
})


    .on('click','#backbtn', function(){
            $('#myModal').hide();
            $('.modal-box').hide();
            $('.modal-backdrop').hide();
            history.go(0) ;
    })
    .on('click', '#myModal', function(){
        $('#myModal').hide();
        $('.modal-box').hide();
        $('.modal-backdrop').hide();
        history.go(0);
    })

    //单个分配
    .on('click','#delete_record', function(){
        // $('.casesure').show();
        // $('.mobile-p').hide();
        $('#deleteModal').modal();

        $("#delete_id").val($(this).attr('record_id'));
    })
    //确认
    .on('click','.deletesure', function(){
        if(lockfas)return;
        lockfas = true;
        $.ajax({
            url: '/entryrepay/delete',
            type: 'post',
            data: {
                'repay_id': $("#delete_id").val()
            },
            dataType: "json",
            success: function(res){
                if(res.code == 200){
                    toastr.success('删除成功');
                    setTimeout(function(){
                        window.location.reload();
                    },3000);

                }else{
                    toastr.error(res.message);
                    lockfas = false;
                }
            },
            error: function(err){
                toastr.error('网络错误,请稍后重试');
                lockfas = false;

            }
        })
    })


